<?php

namespace app\common\service\lib;

class Sign
{
    /**
     * 生成签名
     * @param $data
     * @return array
     */
    public static function getSign($data)
    {
        //生成jwt
        $jwt = Jwt::signToken($data);

        //产生随机数
        $str = randNumber();
        $salt = config('setting.salt').$str;
        //加盐  生成签名
        $sign = base64_encode($jwt['token'].$salt);

        return ['code' => 200, 'data' => [$sign], 'message' => '请求成功'];
    }

    /**
     * 验证签名
     * @param $sign
     * @return array
     */
    public static function checkSign($sign)
    {
        $sign = base64_decode($sign);
        $token = substr($sign,0,config('setting.salt')-1);

        //验证token
        return Jwt::checkToken($token);
    }
}